package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCBorrowReplacementRMAInfo;
import com.shrct.businessprocess.customerservice.RCChildrenReplacementRMAInfo;
import com.shrct.businessprocess.customerservice.RCFaultReport;
import com.shrct.businessprocess.customerservice.RCFaultReportProduct;
import com.shrct.businessprocess.customerservice.RCFaultReportRMAInfo;
import com.shrct.businessprocess.customerservice.RCNormalReplacementRMAInfo;
import com.shrct.businessprocess.customerservice.impl.RCBorrowReplacementRMAInfoImpl;
import com.shrct.businessprocess.customerservice.impl.RCChildrenReplacementRMAInfoImpl;
import com.shrct.businessprocess.customerservice.impl.RCFaultReportImpl;
import com.shrct.businessprocess.customerservice.impl.RCFaultReportRMAInfoImpl;
import com.shrct.businessprocess.customerservice.impl.RCNormalReplacementRMAInfoImpl;
import com.shrct.businessprocess.customerservice.proxy.RCFaultReportProductProxy;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductEntryImpl;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCFAULTREPORTPRODUCT_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcfaultreportproduct")
public class RCFaultReportProductImpl extends BaseModelObject implements RCFaultReportProduct {
  public RCFaultReportProductImpl() {
    super();
  }
  
  public RCFaultReportProductImpl(final RCFaultReport faultReport) {
    super();
    this.faultReport = faultReport;
  }
  
  @JoinColumn(name = "faultReport_id")
  @ManyToOne(targetEntity = RCFaultReportImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCFaultReport faultReport;
  
  public RCFaultReport getFaultReport() {
    return this.faultReport;
  }
  
  public RCFaultReportProduct setFaultReport(final RCFaultReport faultReport) {
    this.faultReport = faultReport;
    return this;			
    
  }
  
  @JoinColumn(name = "product_id")
  @ManyToOne(targetEntity = RCIdentifiablePhysicalProductEntryImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCIdentifiablePhysicalProductEntry product;
  
  public RCIdentifiablePhysicalProductEntry getProduct() {
    return this.product;
  }
  
  public RCFaultReportProduct setProduct(final RCIdentifiablePhysicalProductEntry product) {
    this.product = product;
    return this;			
    
  }
  
  private String comment;
  
  public String getComment() {
    return this.comment;
  }
  
  public RCFaultReportProduct setComment(final String comment) {
    this.comment = comment;
    return this;			
    
  }
  
  private Boolean requireRMA;
  
  public Boolean getRequireRMA() {
    return this.requireRMA;
  }
  
  public RCFaultReportProduct setRequireRMA(final Boolean requireRMA) {
    this.requireRMA = requireRMA;
    return this;			
    
  }
  
  @OneToMany(targetEntity = RCFaultReportRMAInfoImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "product")
  private Collection<RCFaultReportRMAInfo> rmaInfo = new java.util.ArrayList<com.shrct.businessprocess.customerservice.RCFaultReportRMAInfo>();;
  
  public Collection<RCFaultReportRMAInfo> getRmaInfo() {
    return this.rmaInfo;
  }
  
  public RCFaultReportProduct removeAllRmaInfo() {
    for(RCFaultReportRMAInfo obj : this.rmaInfo){
    	getObjectFactory().delete(obj);
    }
    this.rmaInfo.clear();
    return this;	
    
  }
  
  public RCFaultReportProduct removeFromRmaInfo(final RCFaultReportRMAInfo rCFaultReportRMAInfo) {
    this.rmaInfo.remove(rCFaultReportRMAInfo);
    getObjectFactory().delete(rCFaultReportRMAInfo);
    return this;
    
  }
  
  public RCNormalReplacementRMAInfo createNormalRMAFaultReport() {RCNormalReplacementRMAInfo rCNormalReplacementRMAInfo=RCNormalReplacementRMAInfoImpl.create(this,getObjectFactory());
    final Procedure1<RCNormalReplacementRMAInfo> _function = new Procedure1<RCNormalReplacementRMAInfo>() {
        public void apply(final RCNormalReplacementRMAInfo it) {
          RCFaultReportProductImpl.this.faultReport.startDeviceRMA(RCFaultReportProductImpl.this, "\u666E\u901A\u8BBE\u5907RMA");
        }
      };
    RCNormalReplacementRMAInfo _doubleArrow = ObjectExtensions.<RCNormalReplacementRMAInfo>operator_doubleArrow(rCNormalReplacementRMAInfo, _function);
    return _doubleArrow;
  }
  
  public RCBorrowReplacementRMAInfo createBorrowRMAFaultReport() {RCBorrowReplacementRMAInfo rCBorrowReplacementRMAInfo=RCBorrowReplacementRMAInfoImpl.create(this,getObjectFactory());
    final Procedure1<RCBorrowReplacementRMAInfo> _function = new Procedure1<RCBorrowReplacementRMAInfo>() {
        public void apply(final RCBorrowReplacementRMAInfo it) {
          RCFaultReportProductImpl.this.faultReport.startDeviceRMA(RCFaultReportProductImpl.this, "\u501F\u7528\u8BBE\u5907RMA");
        }
      };
    RCBorrowReplacementRMAInfo _doubleArrow = ObjectExtensions.<RCBorrowReplacementRMAInfo>operator_doubleArrow(rCBorrowReplacementRMAInfo, _function);
    return _doubleArrow;
  }
  
  public RCChildrenReplacementRMAInfo createChildrenRMAFaultReport() {RCChildrenReplacementRMAInfo rCChildrenReplacementRMAInfo=RCChildrenReplacementRMAInfoImpl.create(this,getObjectFactory());
    final Procedure1<RCChildrenReplacementRMAInfo> _function = new Procedure1<RCChildrenReplacementRMAInfo>() {
        public void apply(final RCChildrenReplacementRMAInfo it) {
          RCFaultReportProductImpl.this.faultReport.startDeviceRMA(RCFaultReportProductImpl.this, "\u5B50\u8BBE\u5907RMA");
        }
      };
    RCChildrenReplacementRMAInfo _doubleArrow = ObjectExtensions.<RCChildrenReplacementRMAInfo>operator_doubleArrow(rCChildrenReplacementRMAInfo, _function);
    return _doubleArrow;
  }
  
  public String getEntityName() {
    String _entityName = this.product.getEntityName();
    return _entityName;
  }
  
  public static RCFaultReportProduct create(final RCFaultReport faultReport, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.customerservice.RCFaultReportProduct rCFaultReportProduct = new com.shrct.businessprocess.customerservice.impl.RCFaultReportProductImpl(
    	faultReport
    );
    objectFactory.create(rCFaultReportProduct);
    return rCFaultReportProduct;			
    
  }
  
  public static RCFaultReportProduct createRCFaultReportProductImpl(final RCFaultReport faultReport, final IObjectFactory objectFactory, final Procedure1<RCFaultReportProduct> init) {
    com.shrct.businessprocess.customerservice.RCFaultReportProduct rCFaultReportProduct = new com.shrct.businessprocess.customerservice.impl.RCFaultReportProductImpl(
    	faultReport
    );
    objectFactory.create(rCFaultReportProduct);
    init.apply(rCFaultReportProduct);
    
    return rCFaultReportProduct;			
    
  }
  
  public RCFaultReportProductProxy toProxy() {
    com.shrct.businessprocess.customerservice.proxy.RCFaultReportProductProxy proxy = new com.shrct.businessprocess.customerservice.proxy.RCFaultReportProductProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
